package agh.tk.markuptranslation;

public class TableRow extends AbstractComponent
{
	/**
	 * 
	 * @param leftChild - Komorka
	 * @param rightChild - Reszta wiersza
	 */
	public TableRow(IComponent leftChild, IComponent rightChild) 
	{
		super(leftChild, rightChild);
	}
	@Override
	public String toDokuWiki()
	{
		return super.toDokuWiki("|") ;
 	}
	@Override
	public String toMediaWiki()
	{
		return null ;
	}
	
	@Override
	public String toHTML() {
		StringBuilder result = new StringBuilder();
		if(leftChild != null) {
			IComponent temp = rightChild;
			int colspan = 1;
			while(temp != null) {
				if(((AbstractComponent)rightChild).leftChild == null)
					colspan++;
				else 
					break;
				temp = ((AbstractComponent)rightChild).rightChild;
			}
			if(colspan == 1)
				result.append("<td>");
			else {
				result.append("<td colspan=\"");
				result.append(colspan);
				result.append("\">");
			}
			result.append(leftChild.toHTML());
			result.append("</td>");
		}
		if(rightChild!=null)
			result.append(rightChild.toHTML());
		return result.toString();
	}
	
	@Override
	public String toTxt2tags()
	{
		return super.toTxt2tags("|") ;
	}
}
